<?php
/**
 * Created by b17
 * 2/15/12 5:57 PM
 */

namespace Managers\Email;

abstract class Source
{
    /**
     * @var \Zend_Validate_Interface
     */
    protected $validator;

    /**
     * @var \Zend_Filter_Interface
     */
    protected $filter;

    public function __construct()
    {
        $this->setValidator(new \Zend_Validate_EmailAddress());
        $this->setFilter(new DefaultFilters());
        $this->init();
    }

    protected function init()
    {

    }

    public function setFilter(\Zend_Filter_Interface $filter)
    {
        $this->filter = $filter;
    }

    public function setValidator(\Zend_Validate_Interface $validator)
    {
        $this->validator = $validator;
    }

    abstract protected function parse($file);

    public function getParsed($file)
    {
        $parsed = $this->parse($file);
        $result = array();
        foreach ($parsed as $email) {
            if ($this->validator->isValid($email)) {
                $result[] = $this->filter->filter($email);
            }
        }
        return $result;
    }
}
